import 'dart:io';
import 'package:city_corner/commons/global-var.dart';
import 'package:city_corner/commons/my-raised-btn.dart';
import 'package:city_corner/main-page/filter-panel/local-panel/area/index.dart';
import 'package:city_corner/main-page/filter-panel/local-panel/subway/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../opt-list.dart';
import 'near/index.dart';

/**
 * 筛选栏——区域
 */
class LocalPanel extends StatefulWidget {
  @override
  _LocalPanelState createState() => _LocalPanelState();
}

class _LocalPanelState extends State<LocalPanel> {
  List localOpt = [
    {'label': '附近', 'widget': Near()},
    {'label': '区域', 'widget': Area(cityCode: '4401')},
    {'label': '地铁', 'widget': SubWay()},
    // {'label': '学校', 'widget': 'school'}
  ];
  Widget curWidget = SizedBox();

  @override
  void initState() {
    super.initState();
    setState(() {
      curWidget = localOpt[0]['widget'];
    });
  }

  Widget column1() {
    return Row(children: [
      OptList(
          opts: localOpt,
          onPressed: (int index) {
            setState(() {
              curWidget = localOpt[index]['widget'];
            });
          })
    ]);
  }

  Widget bottomPanel() {
    BtnColor btnColor = new BtnColor();

    return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      MyRaisedBtn(text: '重置'),
      MyRaisedBtn(
        text: '提交',
        color: btnColor.orange,
        textColor: 0xffffffff,
      ),
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: [
          Expanded(
              child: Container(
                  width: mediaSize(context).width,
                  child: Row(
                    children: [column1(), curWidget],
                  ))),
          bottomPanel()
        ],
      ),
    );
  }
}
